//This entity is from the Social Mobile Team.
package entity.tx;


import entity.establishment.OutletFood;
import entity.account.Social;
import entity.establishment.Outlet;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author JY
 */
@Entity
public class Places implements Serializable {
//    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String placeName;
    private Double latitude;
    private Double longtitude;
//    @OneToMany(cascade={CascadeType.MERGE}, mappedBy="place")
//    private List<CheckIns> checkIns = new ArrayList<CheckIns>();
    private List photos = new ArrayList();
//    @OneToMany(cascade={CascadeType.MERGE})
//    private List<Social> likes = new ArrayList<Social>();
    @OneToOne(cascade={CascadeType.MERGE})
    private Social creator;
    private Long createdTime;
    
    private String distance; //should NOT store anything at all, for display purposes
    
    @OneToMany(fetch= FetchType.EAGER, cascade={CascadeType.PERSIST}, mappedBy="place")
    private List<Reviews> reviews = new ArrayList<Reviews>();
    private Double rating = new Double(0);
    
    @OneToOne(cascade={CascadeType.PERSIST})
    private Outlet outlet;
    // GETTER/SETTER
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

//    public List<CheckIns> getCheckIns() {
//        return checkIns;
//    }
//
//    public void setCheckIns(List<CheckIns> checkIns) {
//        this.checkIns = checkIns;
//    }

    public Long getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Long createdTime) {
        this.createdTime = createdTime;
    }

//    public Social getCreator() {
//        return creator;
//    }
//
//    public void setCreator(Social creator) {
//        this.creator = creator;
//    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

//    public List<Social> getLikes() {
//        return likes;
//    }
//
//    public void setLikes(List<Social> likes) {
//        this.likes = likes;
//    }

    public Double getLongtitude() {
        return longtitude;
    }

    public void setLongtitude(Double longtitude) {
        this.longtitude = longtitude;
    }

    public List getPhotos() {
        return photos;
    }

    public void setPhotos(List photos) {
        this.photos = photos;
    }

    public String getPlaceName() {
        return placeName;
    }

    public void setPlaceName(String placeName) {
        this.placeName = placeName;
    }

    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }

    public Double getRating() {
        return rating;
    }

    public void setRating(Double rating) {
        this.rating = rating;
    }

    public List<Reviews> getReviews() {
        return reviews;
    }

    public void setReviews(List<Reviews> reviews) {
        this.reviews = reviews;
    }

    public Outlet getOutlet() {
        return outlet;
    }

    public void setOutlet(Outlet outlet) {
        this.outlet = outlet;
    }

    //END OF GETTER/SETTER
    
//    public void createPlace(String placeName, Double latitude, Double longtitude, Social user) {
//        this.placeName = placeName;
//        this.latitude = latitude;
//        this.longtitude = longtitude;
//        this.creator = user;
//        this.createdTime = System.currentTimeMillis()/1000;
//    }
    
    /*public void createPlace(String placeName, Double latitude, Double longtitude, POI poi) {
        this.placeName = placeName;
        this.latitude = latitude;
        this.longtitude = longtitude;
        this.poi = poi;
        this.createdTime = System.currentTimeMillis();
    }*/
    
    public void createPlace(String placeName, Double latitude, Double longtitude, OutletFood outlet) {
        this.placeName = placeName;
        this.latitude = latitude;
        this.longtitude = longtitude;
        this.outlet = outlet;
        this.createdTime = System.currentTimeMillis()/1000;
        this.rating = new Double(0);
    }
    
    public String getCreationTime(String tZone) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone(tZone));
        return sdf.format(new Date(createdTime));
    }

    /**
     * @return the creator
     */
    public Social getCreator() {
        return creator;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Social creator) {
        this.creator = creator;
    }
    
    
    
    
}
